home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c
- Subject: Re: Opening STDOUT As BINARY
- Date: 3 Apr 1996 12:49:22 GMT
- Organization: systems hk
- Message-ID: <4jts4i$h8d@nadine.teleport.com>
- References: <3161CAD8.296C@netrover.com>
- NNTP-Posting-Host: ip-pdx01-07.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- Stephane Charette <charrick@netrover.com> wrote:
- >I've come across a problem, and I believe that it is
- >caused by limitations in C/C++. Can anyone help on the
- >following:
- >
- >I need to output binary information to the console, which
- >is then redirected to a file by the o/s. At the moment,
- >I'm using printf( "%c", mychar ) to output the the binary
- >data one character at a time as it comes in.
- >
- >However, it seems that the character #7 (0x07, bell) gets
- >sent to stdout followed by an automatic CR (0x0A). Every
- >other character in the ASCII table works fine! Is there
- >a way to reopen stdout in binary mode instead of as a text
- >stream? The extra 0x0A characters are corrupting the data!
- >
- >I've also tried "cout" and "putc", but they yield the same
- >result.
- >
- >Why do I need this: this application runs as a CGI-BIN,
- >and the web server EXPECTS the output to be sent to
- >stdout. I cannot fwrite() this information to a physical
- >file since the web server is capturing the console output!
- >
- Stephane,
-
- I know I'll catch hell for this in this group, but the following
- worked for me (using Borland 4.5 on Windows NT). I don't
- know if setmode is a portable/standard function, but perhaps
- something similar exists for you:
-
- if( fInp == stdin ) /* set std-input to binary */
- setmode( 0,O_BINARY );
-
- if( fOut == stdout ) /* set std-output to binary */
- setmode( 1,O_BINARY );
-
- Yours, Geoff Houck
-
-